home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Broderbund Demo / DemoData / dialog / dPrintOF.Dxr / 00003_buttonMan.ls < prev    next >
Encoding:
Text File  |  1997-08-22  |  5.9 KB  |  262 lines

  1. property spriteList, defaultList, downList, overList, greyList, activeList, myType, active, lastSprite, myDown, lastDown, downSound, upSound
  2.  
  3. on new me, theSpriteList, theDefaultList, theCastName
  4.   set spriteList to theSpriteList
  5.   set defaultList to getMemberNumList(theDefaultList, theCastName)
  6.   set active to 0
  7.   set lastSprite to 0
  8.   set myType to 1
  9.   set myDown to 0
  10.   set lastDown to 0
  11.   set activeList to []
  12.   repeat with i = 1 to count(spriteList)
  13.     append(activeList, 1)
  14.   end repeat
  15.   return me
  16. end
  17.  
  18. on setType me, theType
  19.   case theType of
  20.     "radio":
  21.       set myType to 2
  22.     "toggle":
  23.       set myType to 3
  24.     otherwise:
  25.       set myType to 1
  26.   end case
  27. end
  28.  
  29. on setSound me, downSoundP, upSoundP
  30.   set downSound to downSoundP
  31.   set upSound to upSoundP
  32. end
  33.  
  34. on setRadio me, index
  35.   if myDown <> 0 then
  36.     setActive(me, getOne(spriteList, myDown), 1)
  37.   end if
  38.   if index = 0 then
  39.     set myDown to 0
  40.   else
  41.     set myDown to getOne(spriteList, index)
  42.   end if
  43.   set myDown to getOne(spriteList, myDown)
  44.   if myDown <> 0 then
  45.     setActive(me, index, 0)
  46.   end if
  47. end
  48.  
  49. on setState me, activeState
  50.   puppetSprites(spriteList, activeState)
  51.   if activeState then
  52.     unsuspend(me)
  53.   else
  54.     suspend(me)
  55.   end if
  56. end
  57.  
  58. on suspend me
  59.   set r to getOne(the actorList, me)
  60.   if r > 0 then
  61.     deleteAt(the actorList, r)
  62.   end if
  63.   set active to 0
  64. end
  65.  
  66. on unsuspend me
  67.   set r to getOne(the actorList, me)
  68.   if r = 0 then
  69.     append(the actorList, me)
  70.   end if
  71.   set active to 1
  72.   update(me)
  73. end
  74.  
  75. on setDownList me, theDownList, theCastName
  76.   set downList to getMemberNumList(theDownList, theCastName)
  77. end
  78.  
  79. on setOverList me, theOverList, theCastName
  80.   set overList to getMemberNumList(theOverList, theCastName)
  81. end
  82.  
  83. on setGreyList me, theGreyList, theCastName
  84.   set greyList to getMemberNumList(theGreyList, theCastName)
  85. end
  86.  
  87. on setActive me, index, state
  88.   deleteAt(activeList, index)
  89.   addAt(activeList, index, state)
  90. end
  91.  
  92. on setGrey me, index, greyState
  93.   setActive(me, index, not greyState)
  94.   if greyState then
  95.     swapSprite(getAt(spriteList, index), getAt(greyList, index))
  96.   else
  97.     swapSprite(getAt(spriteList, index), getAt(defaultList, index))
  98.   end if
  99.   updateStage()
  100. end
  101.  
  102. on activeClick me
  103.   if active then
  104.     if lastDown = the clickOn then
  105.       if getAt(activeList, getOne(spriteList, the clickOn)) then
  106.         return 1
  107.       else
  108.         return 0
  109.       end if
  110.     end if
  111.   else
  112.     return 0
  113.   end if
  114. end
  115.  
  116. on update me
  117.   repeat with i = 1 to count(activeList)
  118.     if getAt(activeList, i) then
  119.       swapSprite(getAt(spriteList, i), getAt(defaultList, i))
  120.       next repeat
  121.     end if
  122.     if not voidp(greyList) then
  123.       swapSprite(getAt(spriteList, i), getAt(greyList, i))
  124.     end if
  125.   end repeat
  126.   if myType = 2 then
  127.     if myDown <> 0 then
  128.       swapSprite(myDown, getAt(downList, getOne(spriteList, myDown)))
  129.     end if
  130.   end if
  131. end
  132.  
  133. on mMouseDown me
  134.   set theSprite to the clickOn
  135.   if theSprite <> lastSprite then
  136.     mMouseExit(me, lastSprite, 0)
  137.   end if
  138.   set index to getOne(spriteList, theSprite)
  139.   if getAt(activeList, index) then
  140.     if myType = 2 then
  141.       if myDown <> 0 then
  142.         swapSprite(myDown, getAt(defaultList, getOne(spriteList, myDown)))
  143.         setActive(me, getOne(spriteList, myDown), 1)
  144.       end if
  145.       set myDown to theSprite
  146.     end if
  147.     if not voidp(downList) then
  148.       swapSprite(theSprite, getAt(downList, getOne(spriteList, theSprite)))
  149.     end if
  150.     if not voidp(downSound) then
  151.       puppetSound(1, downSound)
  152.     end if
  153.     set lastSprite to theSprite
  154.     set lastDown to theSprite
  155.   end if
  156.   updateStage()
  157. end
  158.  
  159. on mMouseEnter me, theSprite
  160.   if theSprite <> lastSprite then
  161.     mMouseExit(me, lastSprite, 0)
  162.   end if
  163.   set index to getOne(spriteList, theSprite)
  164.   if getAt(activeList, index) then
  165.     if not voidp(overList) then
  166.       swapSprite(theSprite, getAt(overList, getOne(spriteList, theSprite)))
  167.     end if
  168.     set lastSprite to theSprite
  169.   end if
  170.   updateStage()
  171. end
  172.  
  173. on mMouseUp me
  174.   set theSprite to the clickOn
  175.   if theSprite <> lastSprite then
  176.     mMouseExit(me, lastSprite, 0)
  177.   end if
  178.   set index to getOne(spriteList, theSprite)
  179.   if myType = 2 then
  180.     if myDown = theSprite then
  181.       setActive(me, index, 0)
  182.     end if
  183.   end if
  184.   if getAt(activeList, index) then
  185.     if voidp(overList) then
  186.       swapSprite(theSprite, getAt(defaultList, getOne(spriteList, theSprite)))
  187.     else
  188.       swapSprite(theSprite, getAt(overList, getOne(spriteList, theSprite)))
  189.     end if
  190.     if not voidp(upSound) then
  191.       puppetSound(1, upSound)
  192.     end if
  193.     set lastSprite to theSprite
  194.   end if
  195.   updateStage()
  196. end
  197.  
  198. on mMouseExit me, theSprite, update
  199.   if myType = 2 then
  200.     if myDown <> theSprite then
  201.       if lastSprite > 0 then
  202.         swapSprite(theSprite, getAt(defaultList, getOne(spriteList, theSprite)))
  203.       end if
  204.     end if
  205.   else
  206.     if theSprite > 0 then
  207.       swapSprite(theSprite, getAt(defaultList, getOne(spriteList, theSprite)))
  208.     end if
  209.   end if
  210.   set lastSprite to 0
  211.   if update then
  212.     updateStage()
  213.   end if
  214. end
  215.  
  216. on swapSprite theSprite, theMember
  217.   if theSprite <> 0 then
  218.     set the memberNum of sprite theSprite to theMember
  219.   end if
  220. end
  221.  
  222. on stepFrame me
  223.   set r to rollOver()
  224.   if getOne(spriteList, r) = 0 then
  225.     mMouseExit(me, lastSprite, 1)
  226.   else
  227.     if the mouseDown then
  228.       if lastSprite = r then
  229.         nothing()
  230.       else
  231.         mMouseExit(me, lastSprite, 1)
  232.       end if
  233.     else
  234.       if lastSprite = r then
  235.         nothing()
  236.       else
  237.         mMouseEnter(me, r)
  238.       end if
  239.     end if
  240.   end if
  241. end
  242.  
  243. on puppetSprites theList, theState
  244.   repeat with s in theList
  245.     puppetSprite(s, theState)
  246.   end repeat
  247. end
  248.  
  249. on getMemberNumList theMemberList, theCastName
  250.   set newList to []
  251.   if voidp(theCastName) then
  252.     repeat with n in theMemberList
  253.       append(newList, the number of member n)
  254.     end repeat
  255.   else
  256.     repeat with n in theMemberList
  257.       append(newList, the number of member n of castLib theCastName)
  258.     end repeat
  259.   end if
  260.   return newList
  261. end
  262.